package org.example.order;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;

@Component
// 这里指定了 MACHINEID
@WithStateMachine(id = OrderStateMachineBuilder.MACHINEID)               //绑定待监听的状态机
public class OrderEventConfig {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @OnTransition(target = "UNPAID")
    public void create(){
        logger.info("订单创建，待支付!");
    }

    @OnTransition(source = "UNPAID",target = "WAITING_FOR_DELIVER")
    public void pay(){
        logger.info("用户完成支付，待发货!");
    }

    @OnTransition(source = "WAITING_FOR_DELIVER",target = "WAITING_FOR_RECEIVE")
    public void deliver(){
        logger.info("订单已发货，待收货!");
    }

    @OnTransition(source = "WAITING_FOR_RECEIVE",target = "DONE")
    public void receive(){
        logger.info("用户已收货，订单完成!");
    }
}
